package zhaolongli_Boundary;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;

import zhaolongli_Entity.Edge;
import zhaolongli_Entity.Model;


/** present the Decision Lines in a visual way */

public class DrawingCanvas extends Canvas {

	/** Model being viewed. */
	Model m;

	int numColumn;
	
	
	public DrawingCanvas(Model m) {
		this.m = m;
		numColumn = m.getN() - 1;
		repaint();
	}
/**
 * paint method of the Canvas, first time calls it will initialized the line view.
 * 
 */
	@Override	
	public void paint(Graphics sg) {


			int n = m.getN();
			if (n < 3 || n >8) {
				return;
			}
			else if (n == 3){
				sg.drawLine(130, 50, 130, 350);
				sg.drawLine(130+165, 50, 130+165, 350);
				sg.drawLine(130+165*2, 50, 130+165*2, 350);
			}			
			else if (n == 4) {
				sg.drawLine(110, 50, 110, 350);
				sg.drawLine(110 + 125, 50, 110 + 125, 350);
				sg.drawLine(110 + 125 * 2, 50, 110 + 125 * 2, 350);
				sg.drawLine(110 + 125 * 3, 50, 110 + 125 * 3, 350);
			}
			else if (n == 5){
				sg.drawLine(80, 50, 80, 350);
				sg.drawLine(80 + 108, 50, 80 + 108, 350);
				sg.drawLine(80 + 108 * 2, 50, 80 + 108 * 2, 350);
				sg.drawLine(80 + 108 * 3, 50, 80 + 108 * 3, 350);
				sg.drawLine(80 + 108 * 4, 50, 80 + 108 * 4, 350);
			}
			else if (n == 6){
				sg.drawLine(70, 50, 70, 350);
				sg.drawLine(70 + 91, 50, 70 + 91, 350);
				sg.drawLine(70 + 91 * 2, 50, 70 + 91 * 2, 350);
				sg.drawLine(70 + 91 * 3, 50, 70 + 91 * 3, 350);
				sg.drawLine(70 + 91 * 4, 50, 70 + 91 * 4, 350);
				sg.drawLine(70 + 91 * 5, 50, 70 + 91 * 5, 350);
			}
			else if (n == 7){
				sg.drawLine(54, 50, 54, 350);
				sg.drawLine(54 + 81, 50, 54 + 81, 350);
				sg.drawLine(54 + 81 * 2, 50, 54 + 81 * 2, 350);
				sg.drawLine(54 + 81 * 3, 50, 54 + 81 * 3, 350);
				sg.drawLine(54 + 81 * 4, 50, 54 + 81 * 4, 350);
				sg.drawLine(54 + 81 * 5, 50, 54 + 81 * 5, 350);
				sg.drawLine(54 + 81 * 6, 50, 54 + 81 * 6, 350);
			}
			else if (n == 8){
				sg.drawLine(44, 50, 44, 350);
				sg.drawLine(44 + 72, 50, 44 + 72, 350);
				sg.drawLine(44 + 72 * 2, 50, 44 + 72 * 2, 350);
				sg.drawLine(44 + 72 * 3, 50, 44 + 72 * 3, 350);
				sg.drawLine(44 + 72 * 4, 50, 44 + 72 * 4, 350);
				sg.drawLine(44 + 72 * 5, 50, 44 + 72 * 5, 350);
				sg.drawLine(44 + 72 * 6, 50, 44 + 72 * 6, 350);
				sg.drawLine(44 + 72 * 7, 50, 44 + 72 * 7, 350);
			}
			
			// Draw Edges
			
			int i;
			int j;
			Edge tempEdge;

			for(i = 0; i<numColumn; i++ ){
				for(j = 60; j <= 340;j++ ){
					if((tempEdge = (Edge) m.getEdges()[i].get(j)) != null){
						sg.drawLine(m.getOffset()+(m.getGap()*i),
									tempEdge.getHeight(),
									m.getOffset()+(m.getGap()*(i+1)),
									tempEdge.getHeight()	);
					}
				}
			}
		
	}


}
